/**
 * PaperResultQues.java
 * Version 1.0.0
 * Created on 2018年7月18日
 *
 */
package com.yincheng.oes.business.exam.judgepaper.entity;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

/**
 * @author yangsy
 * @version 1.0.0
 * @since
 * 创建时间：2018年7月18日
 * 功能描述：考试成绩题目信息扩展类
 * 邮箱地址：446948434@qq.com
 */
public class PaperResultQues extends PaperResultDetail {

    /**
     * 题目编号
     */
    private String quesCode;

    /**
     * 题目序号
     */
    private Integer quesOrder;

    /**
     * 题目类型，1:A1型题，2:A2型题，3:B型题，4:X型题
     */
    private String quesType;

    /**
     * 选项A
     */
    private String optionA;

    /**
     * 选项B
     */
    private String optionB;

    /**
     * 选项C
     */
    private String optionC;

    /**
     * 选项D
     */
    private String optionD;

    /**
     * 选项E
     */
    private String optionE;

    /**
     * 选项F
     */
    private String optionF;

    /**
     * 正确答案
     */
    private String answer;

    /**
     * 答案解析
     */
    private String analysis;

    /**
     * 得分
     */
    private Float score;

    /**
     * 科目名称
     */
    private String subjectName;

    /**
     * 章节编号
     */
    private Integer chapterCode;

    /**
     * 试卷题目标准分
     */
    private Float standardScore;

    /**
     * 关联的大纲内容
     */
    private List<String> outlineTexts;

    /**
     * 题干信息
     */
    private String stem;

    /**
     * 题目信息
     */
    private String question;

    /**
     * @return the subjectName
     */
    public String getSubjectName() {
        return subjectName;
    }

    /**
     * @param subjectName the subjectName to set
     */
    public void setSubjectName(String subjectName) {
        this.subjectName = subjectName;
    }

    /**
     * @return the chapterCode
     */
    public Integer getChapterCode() {
        return chapterCode;
    }

    /**
     * @param chapterCode the chapterCode to set
     */
    public void setChapterCode(Integer chapterCode) {
        this.chapterCode = chapterCode;
    }

    /**
     * @return the score
     */
    public Float getScore() {
        return score = score == null ? Float.valueOf(0) : score;
    }

    /**
     * @param score the score to set
     */
    public void setScore(Float score) {
        this.score = score;
    }

    /**
     * @return the outlineTexts
     */
    public List<String> getOutlineTexts() {
        if (null == outlineTexts) {
            return new ArrayList<>();
        }
        return outlineTexts;
    }

    /**
     * @param outlineTexts the outlineTexts to set
     */
    public void setOutlineTexts(List<String> outlineTexts) {
        this.outlineTexts = outlineTexts;
    }

    /**
     * @return the answer
     */
    public String getAnswer() {
        if (quesType != null && quesType.equals("4")) {
            if (answer != null) {
                answer = answer.trim().replace(",", "").replace("，", "").toUpperCase();

                String[] arr = answer.split("");
                Arrays.sort(arr, String.CASE_INSENSITIVE_ORDER);
                return StringUtils.join(arr, ",");
            }
        }
        return answer = answer == null ? "" : answer.trim().toUpperCase();
    }

    /**
     * @param answer the answer to set
     */
    public void setAnswer(String answer) {
        this.answer = answer;
    }

    public List<String> getOptions() {
        List<String> options = new ArrayList<String>();
        if (StringUtils.isNotEmpty(optionA)) {
            options.add(optionA);
        }
        if (StringUtils.isNotEmpty(optionB)) {
            options.add(optionB);
        }
        if (StringUtils.isNotEmpty(optionC)) {
            options.add(optionC);
        }
        if (StringUtils.isNotEmpty(optionD)) {
            options.add(optionD);
        }
        if (StringUtils.isNotEmpty(optionE)) {
            options.add(optionE);
        }
        if (StringUtils.isNotEmpty(optionF)) {
            options.add(optionF);
        }
        return options;
    }

    /**
     * @return the quesCode
     */
    public String getQuesCode() {
        return quesCode;
    }

    /**
     * @param quesCode the quesCode to set
     */
    public void setQuesCode(String quesCode) {
        this.quesCode = quesCode;
    }

    /**
     * @return the optionA
     */
    public String getOptionA() {
        return optionA;
    }

    /**
     * @param optionA the optionA to set
     */
    public void setOptionA(String optionA) {
        this.optionA = optionA;
    }

    /**
     * @return the optionB
     */
    public String getOptionB() {
        return optionB;
    }

    /**
     * @param optionB the optionB to set
     */
    public void setOptionB(String optionB) {
        this.optionB = optionB;
    }

    /**
     * @return the optionC
     */
    public String getOptionC() {
        return optionC;
    }

    /**
     * @param optionC the optionC to set
     */
    public void setOptionC(String optionC) {
        this.optionC = optionC;
    }

    /**
     * @return the optionD
     */
    public String getOptionD() {
        return optionD;
    }

    /**
     * @param optionD the optionD to set
     */
    public void setOptionD(String optionD) {
        this.optionD = optionD;
    }

    /**
     * @return the optionE
     */
    public String getOptionE() {
        return optionE;
    }

    /**
     * @param optionE the optionE to set
     */
    public void setOptionE(String optionE) {
        this.optionE = optionE;
    }

    /**
     * @return the optionF
     */
    public String getOptionF() {
        return optionF;
    }

    /**
     * @param optionF the optionF to set
     */
    public void setOptionF(String optionF) {
        this.optionF = optionF;
    }

    /**
     * @return the quesType
     */
    public String getQuesType() {
        return quesType;
    }

    /**
     * @param quesType the quesType to set
     */
    public void setQuesType(String quesType) {
        this.quesType = quesType;
    }

    /**
     * @return the analysis
     */
    public String getAnalysis() {
        return transform(analysis);
    }

    /**
     * @param analysis the analysis to set
     */
    public void setAnalysis(String analysis) {
        this.analysis = analysis;
    }

    /**
     * @return the quesOrder
     */
    public Integer getQuesOrder() {
        return quesOrder;
    }

    /**
     * @param quesOrder the quesOrder to set
     */
    public void setQuesOrder(Integer quesOrder) {
        this.quesOrder = quesOrder;
    }

    private String transform(String str) {
        if (str != null) {
            if (str.contains("<") || str.contains(">") || str.contains("&")) {
                str = str.replaceAll("&", "&amp;");
                str = str.replaceAll("<", "&lt;");
                str = str.replaceAll(">", "&gt;");
            }
        }
        return str;
    }

    /**
     * @return the standardScore
     */
    public Float getStandardScore() {
        return standardScore = standardScore == null ? Float.valueOf(0) : standardScore;
    }

    /**
     * @param standardScore the standardScore to set
     */
    public void setStandardScore(Float standardScore) {
        this.standardScore = standardScore;
    }

    /**
     * @return the question
     */
    public String getQuestion() {
        return question;
    }

    /**
     * @param question the question to set
     */
    public void setQuestion(String question) {
        this.question = question;
    }

    /**
     * @return the stem
     */
    public String getStem() {
        return stem;
    }

    /**
     * @param stem the stem to set
     */
    public void setStem(String stem) {
        this.stem = stem;
    }
}
